package com.baomidou.run.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.run.dto.TbTestDto;
import com.baomidou.run.entity.TbTest;
import com.baomidou.run.service.ITbTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mp
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/tbTest")
public class TbTestController {

    @Autowired
    private ITbTestService iTbTestService;

    /**
     * 分页查询实例
     * @param param 入参
     * @return
     */
    @PostMapping("/selectPage")
    public IPage<TbTest> selectPage(@RequestBody TbTest param){
        try {
            QueryWrapper<TbTest> wrapper = new QueryWrapper<>();
            // 条件拼接（空值忽略的写法）
            wrapper.like(StringUtils.isNotBlank(param.getName()),"name",param.getName());

            Page<TbTest> paramPage = new Page<>(1,1);
            return iTbTestService.page(paramPage,wrapper);
        } catch (Exception e) {
            return null;
        }
    }

    @PostMapping("/selectMpjList")
    public List<TbTestDto> selectMpjList(@RequestBody TbTest param){
        try {
            return iTbTestService.selectMpjList(param);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
